<?php
	include '/public/class_dbmysql.php';
	include '/datacache/public.php';
	$login = $_POST['login'];
	$password1 = $_POST["password"];
	if(!isset($login) || !isset($password1)) {
		echo "<script>alert('Login Failure.');history.go(-1);</script>";
		exit;
	}
	//本地数据库连接
	
	$db = new dbmysql();
	$db->connect(db_host, db_user, db_pw, db_name, db_charset, db_link);
	$db_table = db_prefix . 'regular_member_class';
	$password = md5($password1);
	$db_where =  "name='$login' AND password='$password'";
	$sql = "SELECT *  FROM " . $db_table . " WHERE " .$db_where;
	$rs = $db->query($sql);
	$userinfo = $db->fetch_assoc($rs);
	$count = $db->num_rows($rs);
	if($count <= 0) {
		echo "<script>alert('UserNumber/Password invalid.');history.go(-1);</script>";
		exit;
	}
	//获取卓越账户管理组
	$groupStr = '"' . rtrim($userinfo['managergroup'], ",") . '"';
	$groupStr = str_replace(',','","',$groupStr);
	
?>

<div class="con_text" style="margin-bottom:1px;font-size: 16px;">
Welcome you! Dear Premier Member&nbsp;<?= $userinfo['username'] ?>&nbsp;<a href="index.php?ac=membermain&at=editReguralPassword&u=<?=$userinfo['username']?>" style="font-weight:bold;margin-left: 80px;font-size: 16px;">Change Password</a>
</div>
<br/>
<div>

<hidden id="login" value="<?=$login?>"></hidden>
<hidden id="password" value="<?=$password1?>"></hidden>
<hidden id="lng" value="en" />
	<?php
		$startDate =  isset($_POST['beginDate']) ? $_POST['beginDate']: date("Y-m-d",strtotime("-45 day"));
		$endDate = isset($_POST['endDate']) ? $_POST['endDate'] : date('Y-m-d');
	?>
	StartTime:<input id="d12" value="<?php echo $startDate;?>" name="beginDate" type="text" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'d13\')||\'%y-%M-%d\'}'})"/>
	EndTime:<input id="d13" value="<?php echo $endDate;?>" name="endDate" type="text" 
	onFocus="WdatePicker({minDate:'#F{$dp.$D(\'d12\')}',maxDate:'%y-%M-%d'})" />
	<input type="submit" value="Submit" onclick="query()"/>
</div>
<br/>
<table cellspacing="1" cellpadding="3" border="0" width="50%" style="margin-bottom: 30px;font-size:12px; font-family:Tahoma, Arial, Helvetica, sans-serif;">
    <tbody>
        <tr align="center" style="background-color: #a0a0a0;">
            <td><b>Login</b></td>
			<td><b>Name</b></td>
            <td><b>Balance</b></td>
            <td><b>Equity</b></td>
			<td><b>Profit</b></td>
			<td><b>Margin</b></td>
			
        </tr>
<?php
   
   $db = new dbmysql();
		$db->connect(report_host, report_user, report_pwd, report_dbname, 'utf8', 1);
		$sql = 'SELECT u.login"交易账户",u.name"姓名",u.balance"余额",ROUND(u.equity,2)"净值",ROUND(SUM(d.PROFIT),2)"平仓盈亏",u.margin"占用保证金"
				FROM mt4_users AS u 
				LEFT JOIN mt4_daily AS d
				ON u.login=d.login AND DATE(d.time) >= "' .$startDate. '" AND DATE(d.time) <= "' .$endDate. '" 
				WHERE u.group IN (' . $groupStr . ') 
				GROUP BY u.LOGIN';
        $rs = $db->query($sql);
			$blancesSum = 0;
			$equitySum = 0;
			$profitSum = 0;
			while ($rsList = $db->fetch_assoc($rs)) {
				$profit = empty($rsList["平仓盈亏"]) ? "0.00" : $rsList["平仓盈亏"];
				$blancesSum += $rsList["余额"];
				$equitySum += $rsList["净值"];
				$profitSum += $profit;
				echo '<tr align="center" bgcolor="#cccccc">
		              <td style="font-size:15px">' . $rsList["交易账户"] .'</td>
				      <td style="font-size:15px">' . $rsList["姓名"] .'</td>
		              <td style="font-size:15px">' . $rsList["余额"] .'</td>
		              <td style="font-size:15px">' .$rsList["净值"] .'</td>
                      <td style="font-size:15px">' . $profit .'</td>
					  <td style="font-size:15px">' .$rsList["占用保证金"] .'</td>
					  </tr>';

			}
			echo '<tr align="center" bgcolor="#cccccc">
		              <td style="font-size:15px">Total</td>
				      <td style="font-size:15px"></td>
		              <td style="font-size:15px">' . $blancesSum . '</td>
		              <td style="font-size:15px">' . $equitySum . '</td>
                      <td style="font-size:15px">' . $profitSum . '</td>
					  <td style="font-size:15px"></td>
					  </tr>';
		
		$db->close();
?>
    </tbody>
</table>